package cn.sunflower.exam.controller;

import cn.sunflower.exam.entity.Score;
import cn.sunflower.exam.seivice.ScoreService;
import cn.sunflower.sys.bean.constant.BaseConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 成绩相关的接口
 *
 * @author zhanglf
 */
@RestController
@RequestMapping(value = "${project.prefixApp}/score")
@Api(tags = "成绩分数相关接口")
public class ScoreController{
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ScoreService scoreService;

    @ApiOperation("根据工号查询最近一次成绩")
    @GetMapping("getRecentScore")
    public Map<String,Object> getRecentScore(@ApiParam("工号") String empId) {
        logger.info("根据工号查询最近一次成绩,工号:{}", empId);
        Map<String, Object> result = new HashMap<>();
        if (StringUtils.isEmpty(empId)) {
            logger.info("工号为空");
            result.put(BaseConstant.MSG, "输入参数有误");
            result.put(BaseConstant.RETURN_CODE,BaseConstant.FAIL);
        }else{
            Score score = scoreService.findScoreByEmpId("12039450",null);
            result.put(BaseConstant.DATA, score);
            result.put(BaseConstant.RETURN_CODE,BaseConstant.SUCCESS);
        }
        return result;
    }

}
